iOS Initialization
Here you will learn how to set up all the Group Link iOS SDK functions to run properly in your application.
Step 1 - Initialize the Group Link SDK
Start the library
To initialize the library, a Group Link Token is needed. On your AppDelegate
implementation, import the library, and, in the didFinishLaunchingWithOptions
:
App Delegate (Obj-C) - Implementation
#import "AppDelegate.h"
@import GroupLink;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[GroupLinkSDK startWithToken: @"GROUP_LINK_TOKEN"];
return YES;
}
App Delegate - Implementation
import UIKit
import GroupLink
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ...
GroupLinkSDK.start(token: "GROUP_LINK_TOKEN")
// ...
return true
}
}
SwiftUI App Cycle - Implementation (iOS 14)
import SwiftUI
import GroupLink
@main
struct SwiftUIApp: App {
// ...
init() {
GroupLinkSDK.start(token: "GROUP_LINK_TOKEN")
}
// ...
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Step 2 - Request User Bluetooth Authorization
Anywhere in your App, request authorization to use the user's Bluetooth. If you don't have a Bluetooth manager stack, you just need to call the Group Link framework Bluetooth function, which will request the user authorization to use Bluetooth services. We recommend that you call this function at the start of your application. If you ask for permission after some screen like a login screen, our SDK may not start.
App Delegate (Obj-C) - Implementation
#import "AppDelegate.h"
@import GroupLink;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// The permission is required to start the SDK's Bluetooth manager.
// You can execute it during your app's initialization.
[GroupLinkSDK startBluetooth];
return YES;
}
App Delegate - Implementation
import UIKit
import GroupLink
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// The permission is required to start the SDK's Bluetooth manager.
// You can execute it during your app's initialization.
GroupLinkSDK.startBluetooth()
// ...
return true
}
}
SwiftUI App Cycle - Implementation (iOS 14)
import SwiftUI
import GroupLink
@main
struct SwiftUI_TestApp: App {
// ...
init() {
// The permission is required to start the SDK's Bluetooth manager.
// You can execute it during your app's initialization.
GroupLinkSDK.startBluetooth()
}
// ...
}
If you are already using the CoreBluetooth framework, call this method within the .poweredOn state of your Bluetooth delegate:
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
switch ([central state])
{
case CBCentralManagerStatePoweredOn:
[GroupLinkSDK startBluetooth];
break;
default:
break;
}
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
GroupLinkSDK.startBluetooth()
default:
break
}
}
Remember to always check if the user has granted Bluetooth permission when initializing your application, with the checkBluetooth() SDK function.
App Delegate (Obj-C) - Implementation
#import "AppDelegate.h"
@import GroupLink;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// It is recommended to run this function to check if the user has granted Bluetooth permission.
// This function will not prompt for anything. You must call the startBluetooth() function to request permission.
[GroupLinkSDK checkBluetooth];
return YES;
}
App Delegate - Implementation
import UIKit
import GroupLink
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// It is recommended to run this function to check if the user has granted Bluetooth permission.
// This function will not prompt for anything. You must call the startBluetooth() function to request permission.
GroupLinkSDK.checkBluetooth()
// ...
return true
}
}
SwiftUI App Cycle - Implementation (iOS 14)
import SwiftUI
import GroupLink
@main
struct SwiftUI_TestApp: App {
// ...
init() {
// It is recommended to run this function to check if the user has granted Bluetooth permission.
// This function will not prompt for anything. You must call the startBluetooth() function to request permission.
GroupLinkSDK.checkBluetooth()
}
// ...
}
Step 3 - Request User Location Authorization
Anywhere in your App, request authorization to use the user's location. If you don't have a location manager stack, you just need to call the Group Link framework location function, which will request the user authorization to use location services. We recommend that you call this function at the start of your application. If you ask for permission after some screen like a login screen, our SDK may not start.
App Delegate (Obj-C) - Implementation
#import "AppDelegate.h"
@import GroupLink;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// The permission is required to start the SDK's location manager.
// You can execute it during your app's initialization.
[GroupLinkSDK startLocation];
return YES;
}
App Delegate - Implementation
import UIKit
import GroupLink
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// The permission is required to start the SDK's location manager.
// You can execute it during your app's initialization.
GroupLinkSDK.startLocation()
// ...
return true
}
}
SwiftUI - Implementation (iOS 14)
import SwiftUI
import GroupLink
@main
struct SwiftUI_TestApp: App {
// ...
init() {
// The permission is required to start the SDK's location manager.
// You can execute it during your app's initialization.
GroupLinkSDK.startLocation()
}
// ...
}
Group Link will now start monitoring sensors in range.